package com.rmdjzz.slmmn.controller.admin.leaderboardManagement;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rmdjzz.slmmn.pojo.base.Song;
import com.rmdjzz.slmmn.pojo.vo.SongVo;
import com.rmdjzz.slmmn.service.SongService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @作者 张绍鑫
 * @创建时间 2023/6/8
 */

@Controller
@Api(tags = "榜单管理api文档")
@Slf4j
@RequestMapping("/admin")
public class LeaderboardController {
    @Autowired
    SongService songService;
    @GetMapping("/hot")
    @ResponseBody
    @ApiOperation("热歌前十")
    public List<SongVo> hot(){
        QueryWrapper<Song> songQueryWrapper = new QueryWrapper<>();
        songQueryWrapper.orderByDesc("num");
        List<Song> list = songService.list(songQueryWrapper);
        ArrayList<SongVo> songVos = new ArrayList<>();
        for (int i=0;i<10;i++){
            SongVo songVo = new SongVo();
            Song song = list.get(i);
            songVo.setSongName(song.getSongName());
            songVo.setNum(song.getNum());
            songVos.add(songVo);
        }
        return songVos;
    }
    @GetMapping("/soaring")
    @ResponseBody
    @ApiOperation("飙升前十")
    public List<SongVo> soaring(){
        QueryWrapper<Song> songQueryWrapper = new QueryWrapper<>();
        songQueryWrapper.orderByDesc("heat");
        List<Song> list = songService.list(songQueryWrapper);
        ArrayList<SongVo> songVos = new ArrayList<>();
        for (int i=0;i<10;i++){
            SongVo songVo = new SongVo();
            Song song = list.get(i);
            songVo.setSongName(song.getSongName());
            songVo.setHeat(song.getHeat());
            songVos.add(songVo);
        }
        return songVos;
    }
}
